package com.zhudi.chart.view;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.view.Display;
import android.view.View;

import com.zhudi.chart.AbStrUtil;
import com.zhudi.chart.R;
import com.zhudi.develop.util.ZhudiScreenUtil;

public class ChartViewY extends View {
	private Context context;
//	private int selectI;
	/** 原点的X坐标 */
	public int XPoint;
	/** 原点的Y坐标 及开始坐标*/
	public int YPoint;
	/** X的每个刻度长度 */
	public int XScale;
	/** Y的每个刻度长度 */
	public int YScale;
	/** Y的高度 */
	public int height;
	/** X轴的长度 */
	//public int XLength;
	/**Y轴的长度 */
	public int YLength = 470; 
	public String[] XLabel; // X的刻度
	public String[] YLabel; // Y的刻度
	public String[] Data; // 数据
	public String Title; // 显示的标题
	private List<PointBean> allpoint = new ArrayList<PointBean>();// 保存所以的操作坐标
	private Paint xPaint;
	private Paint yPaint;
	private Paint yTxtPaint;
	public static final int RECT_SIZE = 55;
	private Paint dataPaint;

	private int screenWidth;
	private int screenHeight;

	private String data = "";
	private String dushu = "";
	private float x;
	private float y;
	private Paint ciclePaint;
	/**用于标记纵坐标的单位 false表示显示w true表示显示kwh */
    private boolean flag;
	public ChartViewY(Context context) {
		super(context);
		this.context = context;
	}

	/**
	 * 获取数据
	 * 
	 * @param XLabels
	 *            x轴数据
	 * @param YLabels
	 *            y轴数据
	 * @param AllData
	 *            数据内容
	 * @param display
	 *            屏幕对象
	 * @param YPoint
	 * @param height
	 */
	public void SetInfo(String[] XLabels, String[] YLabels, String[] AllData,
			Display display, int YPoint, int height,boolean flag) {
		XPoint = context.getResources().getInteger(R.integer.ZerotoDot);
		XScale = (ZhudiScreenUtil.getScreenWidth(context) - 40) / 8;
		XLabel = XLabels;
		YLabel = YLabels;
		Data = AllData;
		this.YPoint = YPoint;//
		YLength = height;//
		this.flag = flag;
		YScale = (height - 20) / 4;
		this.height = height;
		this.screenWidth = display.getWidth();
		this.screenHeight = display.getHeight();
	}

	@Override
	protected void onDraw(Canvas canvas) {
		super.onDraw(canvas);// 重写onDraw方法
		setDraw(canvas);
	}

	private void setDraw(Canvas canvas) {
		yTxtPaint = new Paint();
		yTxtPaint.setStyle(Paint.Style.STROKE);
		yTxtPaint.setAntiAlias(true);// 去锯齿
		yTxtPaint.setColor(context.getResources().getColor(R.color.black));// 颜色
		//yTxtPaint.setTextSize(25); // 设置轴文字大小
		yTxtPaint.setTextSize(context.getResources().getInteger(R.integer.yPaintTextSize)); // 设置轴文字大小
		for (int i = 0; i * YScale < YLength; i++) {
			try {
				canvas.drawText(AbStrUtil.getOneString(YLabel[i]) , XPoint - 5,YPoint - i * YScale + 5, yTxtPaint); // 文字
			} catch (Exception e) {
			}
		}
		// 写纵坐标单位--文字
		//yTxtPaint.setTextSize(25); // 设置轴文字大小
		//if (flag) {
		//	canvas.drawText("kwh", XPoint - 5,YPoint - YLength + 10, yTxtPaint); 
		//} else {
		//	canvas.drawText("w", XPoint - 5,YPoint - YLength + 10, yTxtPaint); 
		//}
	}

	@Override
	protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
			int with = XPoint + context.getResources().getInteger(R.integer.YtoX);
			setMeasuredDimension(with, screenHeight);
	}

	@Override
	protected void onScrollChanged(int l, int t, int oldl, int oldt) {
		String tag = "onScrollChanged";
		//Log.e(tag, "Scroll....");
		super.onScrollChanged(l, t, oldl, oldt);
	}

}

